<script type="text/javascript" src="<?php echo $base_url; ?>js/swfupload-jquery/vendor/swfupload/swfupload.js"></script>
<script type="text/javascript" src="<?php echo $base_url; ?>js/swfupload-jquery/vendor/swfupload/swfupload.speed.js"></script>
<script type="text/javascript" src="<?php echo $base_url; ?>js/swfupload-jquery/src/jquery.swfupload.js"></script>

<script type="text/javascript">
	
	jQuery(function(){
		jQuery('#swfupload-control').swfupload({
			upload_url: "<?=$base_url?>admin/jx_upload_doc/",
			file_size_limit : "20 MB",
			file_types : "*.doc;*.docx;*.rtf;*.txt;*.pdf",
			file_types_description : "Document Files",
			file_upload_limit : "0",
			flash_url : "<?=$base_url?>js/swfupload-jquery/vendor/swfupload/swfupload.swf",
			button_image_url : '<?=$base_url?>js/swfupload-jquery/vendor/swfupload/XPButtonUploadText_61x22.png',
			button_width : 61,
			button_height : 22,
			button_placeholder_id : "jx-upload",
			debug: false
		})
		.bind('swfuploadLoaded', function(event){
				jQuery('#log').html(' ');
		})
		.bind('fileQueued', function(event, file){
			//jQuery('#log').append('file queued'+'<br />');
			jQuery(this).swfupload('setPostParams', {
					__csrf: 	"<?=$this->security->get_csrf_hash();?>",
					uid: 		jQuery('#edit_id').val(), 
					token : 	"<?php echo $this->encrypt->encode($this->session->userdata('a_id')); ?>"
			});
			jQuery(this).swfupload('startUpload');
		})
		.bind('fileQueueError', function(event, file, errorCode, message){
			//jQuery('#log').append('error='+message+'<br />');
			jQuery('#progressbar1').html('<font color="#ff0000;">'+message+'</font>');
		})
		.bind('fileDialogStart', function(event){
			//jQuery('#log').append('dialog start'+'<br />');
		})
		.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
			//jQuery('#log').append('dialog complete'+'<br />');
		})
		.bind('uploadStart', function(event, file){
			//jQuery('#log').append('upload start'+'<br />');
		})
		.bind('uploadProgress', function(event, file, bytesLoaded){
			jQuery('#log').html(' ');
			//jQuery('#log').append('progress='+bytesLoaded+'<br />');
			if(file.percentUploaded==100)
			{
					jQuery("#progressbar1").html('<p>'+SWFUpload.speed.formatPercent(file.percentUploaded)+" uploaded..."+'</p>');
					setTimeout('jQuery("#progressbar1").html("");', 5000);
			}
			else
			{
					//jQuery("#progressbar1").html('<p>'+SWFUpload.speed.formatPercent(file.percentUploaded)+" uploaded... ["+SWFUpload.speed.formatTime(file.timeRemaining)+" remaining] (<a href=\"javascript:void(0);\" onclick=\"cancelDocUpload();\" style=\"color:#ff0000;\">Cancel</a>)"+'</p>');
					jQuery("#progressbar1").html('<p>'+SWFUpload.speed.formatPercent(file.percentUploaded)+" uploaded...</p>");
			}
		})
		.bind('uploadSuccess', function(event, file, serverData){
			jQuery('#log2').html(' ');
			//jQuery('#log').append('successfully uploaded'+'<br />');
			var jsonstr = jQuery.parseJSON(serverData);
			if(jsonstr.stat)
			{	
					if(jsonstr.stat=='success' && jsonstr.url)
					{
							jQuery('#view-stored-doc').html('<p><a target=_blank href="'+jsonstr.url+'" title="View stored doc">View stored doc</a></p>');
					}
					else if(jsonstr.stat=='success' && jsonstr.msg)
					{
							jQuery('#progressbar1').html('<font color="#ff0000;">'+jsonstr.jsonstr.msg+'</font>');
					}
			}
		})
		.bind('uploadComplete', function(event, file){
			//jQuery('#log').append('upload completed'+'<br />');
			jQuery(this).swfupload('startUpload');
		})
		.bind('uploadError', function(event, file, errorCode, message){
			//jQuery('#log').append('upload error='+message+'<br />');
			jQuery('#progressbar1').html('<font color="#ff0000;">'+message+'</font>');
		});
	});
	
	jQuery(function(){
		jQuery('#swfupload-control2').swfupload({
			upload_url: "<?=$base_url?>admin/jx_upload_sign/",
			file_size_limit : "2 MB",
			file_types : "*.gif;*.png;*.jpeg;*.jpe;*.jpg",
			file_types_description : "Image files",
			file_upload_limit : "0",
			flash_url : "<?=$base_url?>js/swfupload-jquery/vendor/swfupload/swfupload.swf",
			button_image_url : '<?=$base_url?>js/swfupload-jquery/vendor/swfupload/XPButtonUploadText_61x22.png',
			button_width : 61,
			button_height : 22,
			button_placeholder_id : "jx-upload2",
			debug: false
		})
		.bind('swfuploadLoaded', function(event){
			jQuery('#log2').html('<br/>');
		})
		.bind('fileQueued', function(event, file){
			jQuery(this).swfupload('setPostParams', {
					__csrf: 	"<?=$this->security->get_csrf_hash();?>",
					uid: 		jQuery('#edit_id').val(), 
					token : 	"<?php echo $this->encrypt->encode($this->session->userdata('a_id')); ?>"
			});
			jQuery(this).swfupload('startUpload');
		})
		.bind('fileQueueError', function(event, file, errorCode, message){
			jQuery('#progressbar2').html('<font color="#ff0000;">'+message+'</font>');
		})
		.bind('fileDialogStart', function(event){
		})
		.bind('fileDialogComplete', function(event, numFilesSelected, numFilesQueued){
		})
		.bind('uploadStart', function(event, file){
		})
		.bind('uploadProgress', function(event, file, bytesLoaded){
			if(file.percentUploaded==100)
			{
					jQuery("#progressbar2").html('<p>'+SWFUpload.speed.formatPercent(file.percentUploaded)+" uploaded..."+'</p>');
					setTimeout('jQuery("#progressbar2").html("");', 5000);
			}
			else
			{
					//jQuery("#progressbar2").html('<p>'+SWFUpload.speed.formatPercent(file.percentUploaded)+" uploaded... ["+SWFUpload.speed.formatTime(file.timeRemaining)+" remaining] (<a href=\"javascript:void(0);\" onclick=\"cancelDocUpload();\" style=\"color:#ff0000;\">Cancel</a>)"+'</p>');
					jQuery("#progressbar2").html('<p>'+SWFUpload.speed.formatPercent(file.percentUploaded)+" uploaded...</p>");
			}
		})
		.bind('uploadSuccess', function(event, file, serverData){
			var jsonstr = jQuery.parseJSON(serverData);
			if(jsonstr.stat)
			{	
					if(jsonstr.stat=='success' && jsonstr.thumb)
					{
							jQuery('#view-sign').html('<p><img src="'+jsonstr.thumb+'" /></p>');
					}
					else if(jsonstr.stat=='success' && jsonstr.msg)
					{
							jQuery('#progressbar2').html('<font color="#ff0000;">'+jsonstr.jsonstr.msg+'</font>');
					}
			}
		})
		.bind('uploadComplete', function(event, file){
			jQuery(this).swfupload('startUpload');
		})
		.bind('uploadError', function(event, file, errorCode, message){
			jQuery('#progressbar2').html('<font color="#ff0000;">'+message+'</font>');
		});
	});

</script>

	<style>
		.ui-progressbar-value { background-image: url(<?=$base_url?>images/pbar-ani.gif); }
	</style>